/* fafamtd.p - FIXED ASSET MAINTENANCE - Book Detail Maintenance              */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: fafamtd.p 84284 2018-09-20 10:22:04Z mpx                          $: */
/* REVISION: 9.1      LAST MODIFIED: 08/26/99   BY: PJP *N021*                */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 05/17/00   BY: *M0LJ* Vihang Talwalkar   */
/* REVISION: 9.1      LAST MODIFIED: 07/28/00   BY: *N0BX* Arul Victoria      */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0L0* Jacolyn Neder      */
/* REVISION: 9.1      LAST MODIFIED: 10/16/00   BY: *M0TN* Shilpa Athalye     */
/* REVISION: 9.1      LAST MODIFIED: 01/02/01   BY: *M0YM* Veena Lad          */
/* Revision: 1.15.1.15     BY: Alok Thacker        DATE: 07/02/01 ECO: *M1CS* */
/* Revision: 1.15.1.16     BY: Alok Thacker        DATE: 03/13/02 ECO: *M1NB* */
/* Revision: 1.15.1.17     BY: Mercy Chittilapilly DATE: 09/20/02 ECO: *N1VB* */
/* Revision: 1.15.1.19     BY: Subramanian Iyer    DATE: 10/10/02 ECO: *N1WY* */
/* Revision: 1.15.1.20     BY: Manish Dani         DATE: 12/20/02 ECO: *M1YW* */
/* Revision: 1.15.1.22     BY: Paul Donnelly (SB)  DATE: 06/26/03 ECO: *Q00C* */
/* Revision: 1.15.1.23     BY: Veena Lad           DATE: 10/17/03 ECO: *N2LF* */
/* Revision: 1.15.1.24     BY: Jerome Monteiro     DATE: 10/22/03 ECO: *P15X* */
/* Revision: 1.15.1.25     BY: Vandna Rohira       DATE: 12/17/04 ECO: *P2Z5* */
/* Revision: 1.15.1.28     BY: Reena Ambavi        DATE: 12/17/04 ECO: *P2Z2* */
/* Revision: 1.15.1.29     BY: Sachin Deshmukh     DATE: 03/07/05 ECO: *P34S* */
/* Revision: 1.15.1.30     BY: Jignesh Rachh       DATE: 05/12/05 ECO: *P3L3* */
/* REVISION: 23537     LAST MODIFIED: 10/19/12    BY: ddo                     */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{us/bbi/mfdeclre.i}
{us/gp/gprunpdf.i "mcpl" "p"}

/* EXTERNAL LABEL INCLUDE */
{us/bbi/gplabel.i}
{us/px/pxpgmmgr.i}
{us/px/pxphdef.i pccalcxr}
{us/gp/gpoidfcn.i}  /* Defines nextOidValue() function */

/* --------------------  DEFINE QUERY  ------------------- */
define query q_fab_det
   for fab_det
   scrolling.

/* -----------------  STANDARD VARIABLES  ---------------- */
define variable p-status        as character no-undo.
define variable perform-status  as character format "x(25)"
   initial "first" no-undo.
define variable p-skip-update   like mfc_logical no-undo.
define variable l-rowid         as rowid     no-undo.
define variable l-delete-it     like mfc_logical no-undo.
define variable l-del-rowid     as rowid     no-undo.
define variable l-top-rowid     as rowid     no-undo.
define variable lines           as integer   initial 10 no-undo.
define variable l-found         like mfc_logical no-undo.
define variable pos             as integer   no-undo.
define variable l-first         like mfc_logical no-undo.
define variable l-error         like mfc_logical no-undo.
define variable l-title         as character no-undo.
define variable l-per           as character no-undo.

define variable l_amt_fmt       as character no-undo.
define variable mc-error-number like msg_nbr no-undo.
define variable rndmthd         like rnd_rnd_mthd no-undo.

/* ------------------  BUTTON VARIABLES  ----------------- */
define button b-update label "Update".
define button b-end    label "End".

/* -------------  STANDARD WIDGET VARIABLES  ------------- */
define        variable l-focus              as widget-handle no-undo.
define        variable w-frame              as widget-handle no-undo.

/* ------------------  SCREEN VARIABLES  ----------------- */
define shared variable l-type               as character     format "x(10)" no-undo.
define shared variable l-seq                as integer       format "9999" no-undo.
define shared variable l-id                 as character     format "x(12)" no-undo.
define shared variable l-key                as character     format "x(12)" no-undo.
define shared variable l-flag               like mfc_logical no-undo.

define variable l_basis        as decimal   format "->>>>,>>>,>>9.99<" no-undo.
define variable l_cost         like fab_amt                            no-undo.
define variable l_salvamt      like fab_salvamt                        no-undo.
define variable l_cost_fmt     as character format "x(30)"             no-undo.
define variable l_salvamt_fmt  as character format "x(30)"             no-undo.
define variable l_basis_fmt    as character format "x(30)"             no-undo.
define variable fab_ovramt_fmt as character format "x(30)"             no-undo.
define variable l-err-nbr      as integer   format ">>>>>9" initial 0  no-undo.
define variable l-ovr-flag     like mfc_logical                        no-undo.
define variable l-invalidperiod as logical                             no-undo.
define variable l-leap-yr       as logical                             no-undo.
define variable l_endmthpr      as character                           no-undo.
define variable l_total         as integer                             no-undo.
define variable l-lastdate      as date                                no-undo.
define variable l_defaultyear   as integer                             no-undo.
define variable l_date          as date                                no-undo. 
define        variable l-curr               like currency.currencycode no-undo.
define        variable l-statutory_curr     like glt_curr no-undo.
define        variable l-statpropertyisstat as logical       no-undo.
/* ---------------  Exchange Rate ------------------------ */
define        variable l-bc-rate            like fab_bc_exr_rate no-undo.
define        variable l-bc-ratescale       like fab_bc_exr_ratescale no-undo.
define        variable l-sc-rate            like fab_sc_exr_rate no-undo.
define        variable l-sc-ratescale       like fab_sc_exr_ratescale no-undo.
define        variable vErrorNumber         as integer 						no-undo.
define        variable l_bc_cost            like fab_amt no-undo.
define        variable l_sc_cost            like fab_amt no-undo.
define        variable l_bc_cost_fmt        as character     format "x(30)" no-undo.
define        variable l_sc_cost_fmt        as character     format "x(30)" no-undo.
define        variable l_bc_salvage         like fab_amt no-undo.
define        variable l_sc_salvage         like fab_amt no-undo.
define        variable l_bc_salvage_fmt     as character     format "x(30)" no-undo.
define        variable l_sc_salvage_fmt     as character     format "x(30)" no-undo.
define        variable l_rnd_mthd           like gl_rnd_mthd no-undo.
define        variable l_sc_rnd_mthd        like gl_rnd_mthd no-undo.
define buffer bfab_det for fab_det.
define variable hQADFinancialsLib as handle    no-undo.
define variable l-primary-curr    as character no-undo. 
define variable fab_post_oriden  like mfc_logical no-undo. 
define variable l-tot-cost        like fab_amt no-undo.
define variable l-tot-sal         like fab_salvamt no-undo.
 
/*
define variable l-fab-amt        		like fab_amt 			no-undo.
define variable l-curr 					as character 	no-undo.
define variable l_primary_lccost   like fab_amt 				no-undo.
define variable l_primary_cccost   like fab_amt 				no-undo.
*/
define variable l_primary_book    as character no-undo.   
define variable l_days            as integer   no-undo.
/* ------------------  FRAME DEFINITION  ----------------- */
/* Added side-labels phrase to frame statement             */

define frame f-button
   b-update at 1
   b-end at 10
   with no-box overlay three-d side-labels width 19.

/* CLEAR FRAME REGISTRATION TO TRANSLATE THE FRAME EVERYTIME */
clearFrameRegistration(frame f-button:handle).

/* SET EXTERNAL LABELS */
setFrameLabels(frame f-button:handle).

assign
   l-focus               = b-update:handle in frame f-button
   b-update:width        = 8
   b-update:private-data = "update"
   b-end:width           = 8
   b-end:private-data    = "end".

define frame f-1
   skip(.4)
   fab_fabk_id colon 30
   skip
   fab_date    colon 30
   skip
   fab_famt_id colon 30
   skip
   fab_life    colon 30
   skip
   l-curr      colon 30
   skip
   l_cost      colon 30
   skip
   l_salvamt   colon 30
   skip
   l_basis     colon 30 label "Basis Amount"
   skip
   fab_ovramt  colon 30
   skip
   fab_ovrdt   colon 30
   skip
   fab_post_oriden  colon 30   
   skip
   l-bc-rate   colon 30
   skip
   l_bc_cost	colon 30
   skip
   l_bc_salvage colon 30
   skip
   l-sc-rate  colon 30
   skip
   l_sc_cost	colon 30
   skip    	
   l_sc_salvage colon 30
   with three-d overlay side-labels width 80.

/* CLEAR FRAME REGISTRATION TO TRANSLATE THE FRAME EVERYTIME*/
clearFrameRegistration(frame f-1:handle).

/* SET EXTERNAL LABELS */
setFrameLabels(frame f-1:handle).

run ip-framesetup.

w-frame = frame f-1:handle.
{us/bbi/gprun.i ""fafmtut.p""
         "(w-frame)"}

/* ---------------  PRE PROCESSING INCLUDE  -------------- */
/* VARIABLES FOR FA PERSISTENT PROCEDURES */
{us/gp/gprunpdf.i "fapl" "p"}
for last fab_det
   no-lock
   where fab_det.fab_domain = global_domain and  fab_fa_id = l-id
   and fab_fabk_id = l-type:
end. /* FOR FIRST fab_det */

if not available fab_det
   then
   return.
else 
do:
   l-rowid = rowid(fab_det).
   {us/gp/gprunp.i "fapl" "p" "fa-get-cost"
             "(input  fab_fa_id,
               input  fab_fabk_id,
               output l_cost)"}
   {us/gp/gprunp.i "fapl" "p" "fa-get-basis"
             "(input  fab_fa_id,
               input  fab_fabk_id,
               output l_basis)"}
   {us/gp/gprunp.i "fapl" "p" "fa-get-salvage"
             "(input  fab_fa_id,
               input  fab_fabk_id,
               output l_salvamt)"}
   
   assign 
      l-tot-cost = l_cost
      l-tot-sal  = l_salvamt.
   
   for first fabk_mstr where fabk_mstr.fabk_domain = fab_domain and
      fabk_mstr.fabk_id = fab_fabk_id no-lock:
      for first cu_mstr where cu_mstr.oid_cu_mstr = fabk_mstr.oid_cu_mstr no-lock:
         l-curr = cu_mstr.cu_curr.
      end.
   end.	
end. /* ELSE DO */


          
for first famt_mstr
   no-lock
   where famt_mstr.famt_domain = global_domain and  famt_id = fab_famt_id:
end. /* FOR FIRST famt_mstr */

if not available famt_mstr
   then 
do:
   /* INVALID DEPRECIATION METHOD */
   {us/bbi/pxmsg.i &MSGNUM=4200 &ERRORLEVEL=3}
   leave.
end. /* IF NOT AVAILABLE famt_mstr */

for first fa_mstr
   no-lock
   where fa_mstr.fa_domain = global_domain and  fa_id = l-id:
end. /* FOR FIRST fa_mstr */

for first fabk_mstr where fabk_mstr.fabk_primary = yes 
   and fabk_mstr.fabk_domain = global_domain no-lock,
   first cu_mstr of fabk_mstr no-lock:
   assign 
      l-primary-curr = cu_mstr.cu_curr
      l_primary_book = fabk_id.
end.
		
/* SET DEFAULT EXCHANGE RATE AND SCALE FACTOR */
/* FETCHES THE Statutory CURRENCY */
{us/gp/gprunp.i "fapl" "p" "fa-getstatutorycurrency"
   "(output l-statutory_curr,
     output l-statpropertyisstat)"}					 

/* SET CURRENCY DEPENDENT ROUNDING FORMATS */

/* BC Rounding method */
for first gl_ctrl
   where gl_ctrl.gl_domain = global_domain no-lock:
end. /* FOR FIRST gl_ctrl */

/* TC Rounding method */
if l-curr = gl_base_curr then
do:
   assign 
      l_rnd_mthd = gl_rnd_mthd.
end.
else 
do:
   /* GET ROUNDING METHOD FROM CURRENCY MASTER */
   {us/gp/gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
      "(input l-curr,
        output l_rnd_mthd,
        output mc-error-number)"}
   if mc-error-number <> 0 then 
   do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
   end.
end.
/* SC Rounding method */
if l-statutory_curr = l-curr then
do:
   assign 
      l_sc_rnd_mthd = l_rnd_mthd.
end.
else 
do:
   /* GET ROUNDING METHOD FROM CURRENCY MASTER */
   {us/gp/gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
      "(input l-statutory_curr,
        output l_sc_rnd_mthd,
        output mc-error-number)"}
   if mc-error-number <> 0 then 
   do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
   end.	
end.

fab_post_oriden = fab_post_overridden.   

assign 
   l-bc-rate        = fab_det.fab_bc_exr_rate
   l-bc-ratescale   = fab_det.fab_bc_exr_ratescale
   l-sc-rate        = fab_det.fab_sc_exr_rate
   l-sc-ratescale   = fab_det.fab_sc_exr_ratescale       
   l_cost_fmt       = l_cost:format
   l_bc_cost_fmt    = l_bc_cost:format
   l_sc_cost_fmt    = l_sc_cost:format
   l_salvamt_fmt    = l_salvamt:format
   l_basis_fmt      = l_basis:format
   l_bc_salvage_fmt = l_bc_salvage:format
   l_sc_salvage_fmt = l_sc_salvage:format
   fab_ovramt_fmt   = fab_det.fab_ovramt:format.

/* TC Format */
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_cost_fmt,
                          input        l_rnd_mthd)"}
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_salvamt_fmt,
                          input        l_rnd_mthd)"}
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_basis_fmt,
                          input        l_rnd_mthd)"}
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output fab_ovramt_fmt,
                          input        l_rnd_mthd)"}                          
/* BC Format */
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_bc_cost_fmt,
                          input        gl_rnd_mthd)"}  
/* SC Format */
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_sc_cost_fmt,
                          input        l_sc_rnd_mthd)"}    

/* BC Salvage Format */
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_bc_salvage_fmt,
                          input        gl_rnd_mthd)"}  
/* SC Salvage Format */
{us/bbi/gprun.i ""gpcurfmt.p"" "(input-output l_sc_salvage_fmt,
                          input        l_sc_rnd_mthd)"}    

                      
assign
   l_cost:format       = l_cost_fmt
   l_bc_cost:format    = l_bc_cost_fmt
   l_sc_cost:format    = l_sc_cost_fmt
   l_salvamt:format    = l_salvamt_fmt
   l_basis:format      = l_basis_fmt
   l_bc_salvage:format = l_bc_salvage_fmt
   l_sc_salvage:format = l_sc_salvage_fmt
   fab_ovramt:format   = fab_ovramt_fmt.

/* -------------  END PRE PROCESSING INCLUDE  ------------ */

open query q_fab_det for each fab_det
   where rowid(fab_det) = l-rowid no-lock.

get first q_fab_det no-lock.

l_amt_fmt = l_cost:format in frame f-1.
/*
{us/gp/gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
          "(input base_curr,
            output rndmthd,
            output mc-error-number)"}
if mc-error-number <> 0 then do:
   {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
end.

{us/bbi/gprun.i ""gpcurfmt.p""
          "(input-output l_amt_fmt, input rndmthd)"}
*/
assign
   l_cost:format in frame f-1       = l_amt_fmt
   l_bc_cost:format in frame f-1    = l_bc_cost_fmt
   l_sc_cost:format in frame f-1    = l_sc_cost_fmt
   l_salvamt:format in frame f-1    = l_amt_fmt
   l_basis:format in frame f-1      = l_amt_fmt
   fab_ovramt:format in frame f-1   = l_amt_fmt
   l_bc_salvage:format in frame f-1 = l_bc_salvage_fmt  
   l_sc_salvage:format in frame f-1 = l_sc_salvage_fmt.
main-loop:
do while perform-status <> "end" on error undo:

   run ip-query
      (input-output perform-status,
      input-output l-rowid).

   /* ----------------------  DISPLAY  ---------------------- */
   if (perform-status = "update"
      or  perform-status = "add") and (l-bc-rate = 0 or l-sc-rate = 0) then
   do:
      {us/gp/gprunp.i "fapl" "p" "fa-assign-rate"
   				    	 	"(input l-curr,
									input fa_mstr.fa_acquis_effectivedate,
									input base_curr,
									input l-statutory_curr,
									input yes,
									output l-bc-rate,
									output l-bc-ratescale,
									output l-sc-rate,
									output l-sc-ratescale,	   						
									output vErrorNumber)"}
      if vErrorNumber < 0 then
      do:
         return.
      end.
   end.
   /* calculate BC and SC amount */
   assign 
      l_bc_cost    = l_cost * l-bc-rate * l-bc-ratescale
      l_sc_cost    = l_cost * l-sc-rate * l-sc-ratescale
      l_bc_salvage = l_salvamt * l-bc-rate * l-bc-ratescale
      l_sc_salvage = l_salvamt * l-sc-rate * l-sc-ratescale.
   display l-bc-rate
      l_bc_cost
      l-sc-rate
      l_sc_cost
      l_bc_salvage
      l_sc_salvage
      with frame f-1.
   run ip-predisplay.
   
   if (perform-status = "update"
      or  perform-status = "add")
   then do:
      run ip-prompt.
      /* l-flag IS SET TO yes IN BATCH MODE IN PROCEDURE ip-prompt */
      /* FOR AN ERROR ENCOUNTERED.                                 */
      if l-flag
      then
         return.

      if perform-status = "undo"
      then do:
         perform-status = "first".
         next main-loop.
      end. /* IF PERFORM-STATUS = "undo" */

      run ip-displayedits.
   end. /* IF (PERFORM-STATUS = "update" ... */

   /* -----------------------  End  ----------------------- */
   if perform-status = "end"
   then do:
      hide frame f-1 no-pause.
      delete PROCEDURE this-procedure no-error.
      leave.
   end. /* IF PERFORM-STATUS = "end" */

   /* ----------------  SELECTION BUTTONS  ---------------- */
   if perform-status <> "first"
   then
      run ip-button (input-output perform-status).

   /* DETERMINE IF OVERRIDE DEPRECIATION DATE AND ACCUMULATED      */
   /* DEPRECIATION AMOUNT CAN BE UPDATED OR NOT                    */
   /* IF l-ovr-flag IS EQUAL TO YES THEN UPDATION IS NOT ALLOWED   */
   /* IF l-ovr-flag IS EQUAL TO NO THEN UPDATION IS ALLOWED        */
   l-ovr-flag = if can-find
      (first fabk_mstr
      where fabk_mstr.fabk_domain = global_domain and  fabk_id =
      fab_fabk_id
      and fabk_post = no)
      then
      no
      else
         if available fa_mstr
            and (fa_acq_post
            or   fa_post)
         then
            yes
      else
      no.

   if l-ovr-flag
      and perform-status = "update"
   then do:
      /* CANNOT UPDATE- ASSET HAS BEEN POSTED */
      {us/bbi/pxmsg.i &MSGNUM=3281 &ERRORLEVEL=4}
      perform-status = "first".
   end. /* IF l-ovr-flag ... */
end. /* MAIN-LOOP: */

/* -------------  Add / Update / Field Edits  ------------ */
PROCEDURE ip-prompt:
   if perform-status = "add"
   then
      clear frame f-1 all no-pause.
   l-first = yes.
   CASE perform-status:
      when ("add") then
         /* ADDING NEW RECORD */
         {us/bbi/pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      when ("update") then
         /* MODIFYING EXISTING RECORD */
         {us/bbi/pxmsg.i &MSGNUM=10 &ERRORLEVEL=1}
      otherwise
      hide message no-pause.
   END CASE.

   ststatus = stline[3].
   status input ststatus.
   prompt-for-it:
   repeat:
      l-first = no.
      repeat:	
         if available fa_mstr 
            and fa_mstr.fa_post = no 
         then
            prompt-for
               l_cost		
               with frame f-1.
		       
         assign 
            l_basis   = input frame f-1 l_cost - l_salvamt
            l_bc_cost = input frame f-1 l_cost * l-bc-rate * l-bc-ratescale
            l_sc_cost = input frame f-1 l_cost * l-sc-rate * l-sc-ratescale.
         display l_basis l_bc_cost l_sc_cost 
            with frame f-1.

         /* FIELD EDIT FOR l_cost */
         l-error = no.
         {us/bbi/gprun.i ""gpcurval.p""
            "(input  input frame f-1 l_cost,
             input  l_rnd_mthd,
             output l-err-nbr)"}

         if l-err-nbr <> 0
         then
            l-error = yes.

         l-err-nbr = 0.

         /* l-flag IS SET TO yes IN BATCH MODE. */
         if l-error
         then do:

            if not batchrun
            then do:
               next-prompt l_cost with frame f-1.
               next.
            end. /* IF NOT batchrun */
            else 
            do:
               l-flag = yes.
               return.
            end. /* ELSE batchrun */

         end. /* IF l-error THEN */         
         else 
         do:
            assign 
               l_cost = input frame f-1 l_cost.
         end.

         if input frame f-1 l_cost < 0
         then do:
 
            /* THE COST VALUE CANNOT LESS THAN ZERO */
            {us/bbi/pxmsg.i &MSGNUM=228 &ERRORLEVEL=3}

            /* l-flag IS SET TO yes IN BATCH MODE. */
            if not batchrun then 
            do:
               next-prompt l_cost with frame f-1.
               next.
            end. /* IF NOT batchrun */
            else 
            do:
               assign 
                  l-flag = yes.
               return.
            end. /* ELSE DO */
         end.
		
         /* END FIELD EDIT FOR l_salvamt */	
 
     repeat:
        if available fa_mstr 
           and fa_mstr.fa_post = no
        then 
            prompt-for
                l_salvamt		
                with frame f-1. 

         assign 
            l_salvamt = input frame f-1 l_salvamt.
         assign 
            l_bc_salvage = l_salvamt * l-bc-rate * l-bc-ratescale
            l_sc_salvage = l_salvamt * l-sc-rate * l-sc-ratescale
            l_basis      = l_cost - l_salvamt.
         display l_basis l_bc_salvage l_sc_salvage 
            with frame f-1.

         /* FIELD EDIT FOR l_salvamt */
         l-error = no.
         {us/bbi/gprun.i ""gpcurval.p""
                  "(input  input frame f-1 l_salvamt,
                    input  l_rnd_mthd,
                    output l-err-nbr)"}

         if l-err-nbr <> 0
         then
            l-error = yes.

         l-err-nbr = 0.

         if input frame f-1 l_salvamt < 0
         then do:
             assign l-error = yes.
            /* THE COST VALUE CANNOT LESS THAN ZERO */
            {us/bbi/pxmsg.i &MSGNUM=228 &ERRORLEVEL=3}
        end.
        
        if input frame f-1 l_salvamt > input frame f-1 l_cost
         then do:
             assign l-error = yes.
            /* Salvage value exceeds book cost. */
            {us/bbi/pxmsg.i &MSGNUM=13566 &ERRORLEVEL=3}
        end.
        
        

         /* l-flag IS SET TO yes IN BATCH MODE. */
         if l-error
         then do:

            if not batchrun
            then do:
               next-prompt l_salvamt with frame f-1.
               next.
            end. /* IF NOT batchrun */
            else 
            do:
               l-flag = yes.
               return.
            end. /* ELSE batchrun */

         end. /* IF l-error THEN */         
         /* END FIELD EDIT FOR l_salvamt */
         leave.
     end.
	  if l_cost <> 0
      then do: 
         prompt-for
            fab_det.fab_ovramt
            when (l-ovr-flag = no)
            fab_det.fab_ovrdt
            when (l-ovr-flag = no)
            fab_post_oriden       
            with frame f-1.
	  	  
         prompt-for-lc:
         repeat:
            if l-curr = base_curr then leave.
            do with frame f-1:
               prompt-for
                  l-bc-rate.
               if input frame f-1 l-bc-rate = 0 or input frame f-1 l-bc-rate = ?
               then do:
                  {us/bbi/pxmsg.i &MSGNUM=3118 &ERRORLEVEL=3}
                  next-prompt l-bc-rate with frame f-1.
                  next.
               end.
               assign 
                  l_bc_cost    = l_cost * input frame f-1 l-bc-rate * l-bc-ratescale
                  l_bc_salvage = l_salvamt * input frame f-1 l-bc-rate * l-bc-ratescale.
               display l_bc_cost l_bc_salvage.
            end.
            leave.
         end.
         /* statutory currency equal base currency */
         if base_curr = l-statutory_curr then do:
            assign l-sc-rate = input frame f-1 l-bc-rate
                   l_sc_cost    = l_cost * input frame f-1 l-bc-rate * l-sc-ratescale
                   l_sc_salvage = l_salvamt * input frame f-1 l-bc-rate * l-sc-ratescale.
            display l-sc-rate
                    l_sc_cost
                    l_sc_salvage with frame f-1.
         end.
         prompt-for-cc:
         repeat:
            if l-curr = l-statutory_curr then leave.
            do with frame f-1:
               prompt-for
                  l-sc-rate 
                  when l-statpropertyisstat = true.
               if input frame f-1 l-sc-rate = 0 or input frame f-1 l-sc-rate = ?
               then do:
                  {us/bbi/pxmsg.i &MSGNUM=3118 &ERRORLEVEL=3}
                  next-prompt l-sc-rate with frame f-1.
                  next.
               end.
               assign 
                  l_sc_cost    = l_cost * input frame f-1 l-sc-rate * l-sc-ratescale
                  l_sc_salvage = l_salvamt * input frame f-1 l-sc-rate * l-sc-ratescale.
               display l_sc_cost l_sc_salvage.
            end.
            leave.
         end.
	       
         fab_post_oriden = input frame f-1 fab_post_oriden.  
         if input frame f-1 fab_det.fab_ovramt = 0 then fab_post_oriden = no.

         /* FIELD EDIT FOR fab_ovramt */
         l-error = no.
         /* CHECK CURRENCY DEPENDENT ROUNDING FORMAT */
         {us/bbi/gprun.i ""gpcurval.p""
                  "(input  input frame f-1 fab_ovramt,
                    input  l_rnd_mthd,
                    output l-err-nbr)"}

         if l-err-nbr <> 0
         then
            l-error = yes.

         l-err-nbr = 0.

         /* l-flag IS SET TO yes IN BATCH MODE. */
         if l-error
         then do:

            if not batchrun
            then do:
               next-prompt fab_ovramt with frame f-1.
               next.
            end. /* IF NOT batchrun */
            else 
            do:
               l-flag = yes.
               return.
            end. /* ELSE batchrun */

         end. /* IF l-error THEN */
         /* END FIELD EDIT FOR fab_ovramt */

         /* FIELD EDIT FOR fab_ovrdt */
         l-error = no.

         for first fabk_mstr
            no-lock
            where fabk_mstr.fabk_domain = global_domain and  fabk_id =
            fab_fabk_id:

            /* GETTING THE LAST YEAR PERIOD OF BOOK DEPRECIATION */
            find last  fabd_det
               where fabd_domain  =  global_domain
               and   fabd_fa_id   =  fa_mstr.fa_id
               and   fabd_fabk_id =  fabk_id
               no-error.
            if available fabd_det
            then
               assign l_endmthpr = fabd_det.fabd_yrper.

            l_total = 0.

            {us/gp/gprunp.i "fapl" "p" "fa-conv-per-to-enddate"
                      "(input  fabk_calendar,
                        input  l_endmthpr,
                        output l-lastdate,
                        output l-err-nbr)"}

            /* THIS YEAR IS NOT YET DEFINED IN THE SYSTEM, SO USE THE DEFAULT YEAR */
            if l-lastdate = ? 
            then do:
               find first fact_ctrl 
                  where fact_ctrl.fact_domain = global_domain 
               no-lock.
               if available fact_ctrl 
               then 
                  l_defaultyear = fact_ctrl.fact__int01.
               for first glc_cal
                  where glc_cal.glc_domain = global_domain
                  and   glc_year           = l_defaultyear
                  and   glc_per            = integer(substring(l_endmthpr,5,2))
               no-lock:
                  assign
                  l_date  = glc_end.
               end. /* FOR FIRST glc_cal */
               if l_date <> ? 
               then do:
                  l_days = day(l_date).  
                  if l_days = 29
                  then do:
                     l-lastdate = date(month(l_date),l_days,integer(substring(l_endmthpr,1,4))) no-error.
                     if error-status:error = yes 
                     then 
                        assign 
                           l_days     = l_days - 1
                           l-lastdate = date(month(l_date),l_days,integer(substring(l_endmthpr,1,4))).
                  end. /* IF l_days = 29  */
                  else
                     assign 
                        l-lastdate = date(month(l_date),l_days,integer(substring(l_endmthpr,1,4))).
               end. /* IF l_date <> ? */
            end.

            /* CALCULATING THE TOTAL NUMBER OF DAYS BETWEEN THE END DATE AND START DATE OF DEPRICIATION SCHEDULE */
            assign
               l_total = (l-lastdate - fa_mstr.fa_startdt)
               l-invalidperiod = l_total < (input frame f-1 fab_det.fab_ovrdt - fa_mstr.fa_startdt).

            if  l-invalidperiod = yes
               or (input frame f-1 fab_det.fab_ovrdt = ?
               and input frame f-1 fab_ovramt <> 0)
            then do:
               l-error = yes.
               /* DATE NOT WITHIN A VALID PERIOD */
               {us/bbi/pxmsg.i &MSGNUM=3018 &ERRORLEVEL=3}
            end. /* IF  l-per = "" */
         end. /* FOR FIRST fabk_mstr  */

         /* l-flag IS SET TO yes IN BATCH MODE. */
         if l-error
         then do:

            if not batchrun
            then do:
               next-prompt fab_ovrdt with frame f-1.
               next.
            end. /* IF NOT batchrun */
            else 
            do:
               l-flag = yes.
               return.
            end. /* ELSE batchrun */

         end. /* IF l-error THEN */
         /* END FIELD EDIT FOR fab_ovrdt */

         if  input frame f-1 fab_ovramt    <= 0
            and input frame f-1 fab_ovrdt     <> ?
         then do:
            /* OVERRIDE AMOUNT MUST BE GREATER THEN ZERO */
            {us/bbi/pxmsg.i &MSGNUM=4393 &ERRORLEVEL=3}

            /* l-flag IS SET TO yes IN BATCH MODE.       */
            if not batchrun
            then do:
               next-prompt fab_ovramt with frame f-1.
               next.
            end. /* IF NOT batchrun */
            else 
            do:
               l-flag = yes.
               return.
            end. /* ELSE batchrun */

         end. /* IF input frame f-1 fab_ovramt <= 0 */
         
         for first famt_mstr
            where famt_domain = global_domain
            and   famt_id     = fab_famt_id
            no-lock:
         end. /* FOR FIRST famt_mstr ... */

         if available(famt_mstr)
         then do:

            if famt_salv
            then do:

               for first fa_mstr
                  where fa_domain = global_domain
                  and   fa_id     = fab_fa_id
                  no-lock:
               end. /* FOR FIRST fa_mstr ... */

               if available(fa_mstr)
               then do:

                  if l_cost - l_salvamt < input frame f-1 fab_ovramt
                  then do:

                     /* DEPRECIABLE BASIS MUST BE GREATER THAN 0 */
                     {us/bbi/pxmsg.i &MSGNUM=3192 &ERRORLEVEL=3}

                     if not batchrun
                     then do:
                        next-prompt fab_ovramt with frame f-1.
                        next prompt-for-it.
                     end. /* IF NOT batchrun */
                     else 
                     do:
                        l-flag = yes.
                        return.
                     end. /* ELSE batchrun */

                  end. /* IF fab_amt - fa_salvamt < ... */

               end. /* IF AVAILABLE(fa_mstr) */

            end. /* IF famt_salv */
            else
            do:

               if l_cost < input frame f-1 fab_ovramt
               then do:

                  /* DEPRECIABLE BASIS MUST BE GREATER THAN 0 */
                  {us/bbi/pxmsg.i &MSGNUM=3192 &ERRORLEVEL=3}

                  if not batchrun
                  then do:
                     next-prompt fab_ovramt with frame f-1.
                     next prompt-for-it.
                  end. /* IF NOT batchrun */
                  else 
                  do:
                     l-flag = yes.
                     return.
                  end. /* ELSE batchrun */

               end. /* IF fab_amt < INPUT FRAME f-1 fab_ovramt */

            end. /* ELSE ... */

         end. /* IF AVAILABLE(famt_mstr) */
      end. /* IF l_cost <> 0 */
         leave.

      end. /* REPEAT: */

      if keyfunction(lastkey) = "end-error"
      then do:
         perform-status = "undo".
         return no-apply.
      end. /* IF KEYFUNCTION(lastkey) = "end-error" */
      leave.
   end. /* PROMPT-FOR-IT */

   if keyfunction(lastkey) = "end-error"
   then do:
      if perform-status = "add"
      then do:
         /* RECORD NOT ADDED */
         {us/bbi/pxmsg.i &MSGNUM=1304 &ERRORLEVEL=1}
      end. /* IF perform-status = "add" */

      perform-status = "first".
      clear frame f-1.
      get current q_fab_det no-lock.
      run ip-displayedits.
      return.
   end. /* IF KEYFUNCTION(lastkey) = "end-error" */
   run ip-lock
      (input-output perform-status).
END PROCEDURE.

/* -----------------------  LOCKING  ----------------------- */
PROCEDURE ip-lock:
   define input-output parameter perform-status as character no-undo.

   if perform-status = "add"
      or perform-status = "update"
      or perform-status = "delete"
   then
   ip-lock:
   do transaction on error undo:
      assign
         pos         = 0
         l-delete-it = yes.

      if available fab_det
      then
         get current q_fab_det no-lock.

      if available fab_det
         and current-changed fab_det
      then do:
         l-delete-it = yes.
         /* RECORD HAS BEEN MODIFIED SINCE YOU EDITED IT */
         {us/bbi/pxmsg.i &MSGNUM=2042 &ERRORLEVEL=1 &CONFIRM=l-delete-it
                  &CONFIRM-TYPE='LOGICAL'}
         if l-delete-it = no
         then do:
            hide message no-pause.
            run ip-displayedits.
            return.
         end. /* IF l-delete-it = no */

         hide message no-pause.
      end. /* IF AVAILABLE fab_det */

      if available fab_det then
      tran-lock:
      do while perform-status <> "":
         get current q_fab_det exclusive-lock no-wait.

         if locked fab_det
         then do:

            if pos < 3
            then do:
               pos = pos + 1.
               pause 1 no-message.
               next tran-lock.
            end. /* IF pos < 3 */

            perform-status = "error".
         end. /* IF LOCKED fab_det */
         leave.
      end. /* TRAN-LOCK */

      if (perform-status = "update"
         or p-status    = "update")
         and l-delete-it  = yes
      then
         run ip-update (input-output perform-status).

      if perform-status = "delete"
      then
         run ip-delete (input-output perform-status).

      if available fab_det
      then
         get current q_fab_det no-lock.

      if perform-status = "add"
      then
         run ip-add (input-output perform-status).

      /* --------------  /* LOCKED-EDITS */  ------------- */
      if perform-status = "undo"
      then
         undo ip-lock, return.
   /* ------------  END /* LOCKED-EDITS */  ----------- */
   end. /* IP-LOCK: */
END PROCEDURE.

PROCEDURE ip-update:
   define input-output parameter perform-status as character no-undo.

   if p-status = "update"
   then
      p-status = "".

   run ip-assign (input-output perform-status).

   if perform-status = "undo"
   then
      return.

   perform-status = "open".
   run ip-query
      (input-output perform-status,
      input-output l-rowid).
END PROCEDURE.

PROCEDURE ip-add:
   define input-output parameter perform-status as character no-undo.

   create fab_det. 
   fab_det.fab_domain = global_domain.
   run ip-assign (input-output perform-status).
   if perform-status = "undo"
   then
      return.
   perform-status = "open".
   run ip-query
      (input-output perform-status,
      input-output l-rowid).
   perform-status = "first".
   return.
END PROCEDURE.

PROCEDURE ip-delete:
   define input-output parameter perform-status as character no-undo.
   l-delete-it = no.

   /* PLEASE CONFIRM DELETE */
   {us/bbi/pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=l-delete-it
            &CONFIRM-TYPE='LOGICAL'}
   CASE l-delete-it:
      when yes
      then 
         do:


            hide message no-pause.
            delete fab_det.
            clear frame f-1 no-pause.
            get next q_fab_det no-lock.

            if available fab_det
            then
               assign
                  perform-status = "first"
                  l-rowid        = rowid(fab_det).
            else 
            do:
               get prev q_fab_det no-lock.
               if available fab_det
               then
                  assign
                     perform-status = "first"
                     l-rowid        = rowid(fab_det).
               else
                  assign
                     perform-status = "first"
                     l-rowid        = rowid(fab_det).
            end. /* ELSE DO: */

            /* RECORD DELETED */
            {us/bbi/pxmsg.i &MSGNUM=22 &ERRORLEVEL=1}
            return.
         end. /* WHEN YES */
      otherwise
      run ip-displayedits.
   END CASE.
END PROCEDURE.

PROCEDURE ip-assign:
   define input-output parameter perform-status as character no-undo.
   define buffer bfabk_mstr for fabk_mstr.
   define buffer bfa_mstr for fa_mstr.
   define buffer bfad_det for fad_det.
   define variable delta_cost like fa_mstr.fa_puramt no-undo.
   define variable l-seq          like fabd_seq      no-undo.
   define variable l_post_yrper   like fabd_yrper    no-undo.
   define variable l_error        as   integer       no-undo.

   
   do with frame f-1:
      assign
         fab_det.fab_ovramt
         fab_det.fab_ovrdt
         l-rowid                      = rowid(fab_det)
         fab_det.fab_post_overridden  = fab_post_oriden.
         
      if    l-tot-cost <> l_cost 
         or l-tot-sal  <> l_salvamt
      then do:         
         assign    
             l-bc-rate
             l-sc-rate
             l_salvamt         
             fab_det.fab_bc_exr_rate      = l-bc-rate
             fab_det.fab_sc_exr_rate      = l-sc-rate
             fab_det.fab_bc_exr_ratescale = l-bc-ratescale
             fab_det.fab_sc_exr_ratescale = l-sc-ratescale
             fab_det.fab_salvamt          = l_salvamt
             fab_det.fab_amt              = l_cost.
         
         
          /* Once primary book cost or salvage has been changed, change it in the header also */
          for first bfabk_mstr where bfabk_mstr.fabk_domain = global_domain and
            bfabk_mstr.fabk_id = fab_det.fab_fabk_id and
            bfabk_mstr.fabk_primary = yes no-lock:
                
            for first bfa_mstr 
                where bfa_mstr.fa_domain = global_domain and
                        bfa_mstr.fa_id     = fab_det.fab_fa_id 
                exclusive-lock:

                       
                assign delta_cost          = fab_det.fab_amt - bfa_mstr.fa_puramt
                       bfa_mstr.fa_puramt  = fab_det.fab_amt
                       bfa_mstr.fa_salvamt = fab_det.fab_salvamt.
                       
                for first bfad_det
                    where bfad_det.fad_domain = global_domain and
                          bfad_det.fad_fa_id  = fab_det.fab_fa_id 
                    exclusive-lock:
                    assign bfad_det.fad_puramt = bfad_det.fad_puramt + delta_cost.     
                end.        
            end.                            
          end. 

          find first fa_mstr 
             where fa_domain = global_domain and
             fa_id     = fab_det.fab_fa_id no-lock.
          {us/bbi/gprun.i ""fadpbla.p""
             "(input  yes,
               input  fab_det.fab_resrv,
               buffer fa_mstr,
               buffer fab_det,
               input  0,
               input  no,
               output l-err-nbr)"}
      end. /*l-tot-cost       <> l_cost */
      

      for first fa_mstr
         where fa_mstr.fa_domain = global_domain
         and   fa_mstr.fa_id     = fab_det.fab_fa_id
         exclusive-lock:

         for first famt_mstr
            where famt_domain = global_domain
            and   famt_id     = fab_det.fab_famt_id
            no-lock:
         end. /* FOR FIRST famt_mstr */

         if available(famt_mstr)
         then do:

            if famt_salv
            then do:

               if fab_det.fab_amt
                  - fa_mstr.fa_salvamt
                  - fab_det.fab_ovramt
                  = 0
                  and can-find(first fabk_mstr
                  where fabk_domain = global_domain
                  and   fabk_id     = fab_det.fab_fabk_id
                  and   fabk_post
                  and   fabk_primary)
               then do:

                  fa_mstr.fa_post = yes.

               end. /* IF fab_det.fab_amt - fa_salvamt ... */

            end. /* IF famt_salv ... */
            else
            do:

               if fab_det.fab_amt
                  - fab_det.fab_ovramt
                  = 0
                  and can-find(first fabk_mstr
                  where fabk_domain = global_domain
                  and   fabk_id     = fab_det.fab_fabk_id
                  and   fabk_post
                  and   fabk_primary)
               then do:

                  fa_mstr.fa_post = yes.

               end. /* IF fab_det.fab_amt - fab_det.fab_ovramt ... */

            end. /* ELSE ... */

         end. /* IF AVAILABLE(famt_mstr) */

      end. /* FOR FIRST fa_mstr */
      
      /* WHEN SECONDARY POSTING BOOK IS MADE 0, THERE NEEDS TO BE ONE */
      /* FABD_DET RECORD TO ENABLE DEPRECIATION DEVIATION POSTING     */
      if l_cost = 0 
         and can-find (first fabk_mstr no-lock
	                  where fabk_mstr.fabk_domain  = global_domain 
			    and fabk_mstr.fabk_id      = fab_det.fab_fabk_id 
			    and fabk_mstr.fabk_primary = false 
			    and fabk_mstr.fabk_delta   = true)
      then do:
         if can-find (first bfab_det 
	                 where bfab_det.fab_domain  = global_domain 
                           and bfab_det.fab_fa_id   = fab_det.fab_fa_id 
		           and bfab_det.fab_fabk_id = l_primary_book
		           and bfab_det.fab_amt    <> 0 no-lock)
         then do:
            {us/gp/gprunp.i "fapl" "p" "fa-get-per"
                     "(input  fab_det.fab_date,
                       input  '',
                       output l_post_yrper,
                       output l_error)"}
            if l_error <> 0
            then
               return.

            for first bfa_mstr 
	       where bfa_mstr.fa_domain = global_domain 
	         and bfa_mstr.fa_id     = fab_det.fab_fa_id 
            no-lock:
	    end.
	    if not available bfa_mstr 
	    then 
	       return.

            if not can-find (first fabd_det
                               where   fabd_det.fabd_domain = global_domain 
                                 and   fabd_fa_id           = bfa_mstr.fa_id
                                 and   fabd_fabk_id         = fab_det.fab_fabk_id
                                 and   fabd_yrper           = l_post_yrper
                                 and   fabd_entity          = bfa_mstr.fa_entity
		                 and   fabd_post            = no
                             )
               and bfa_mstr.fa_dep = true
            then do:   /* CREATE fabd_det with 0 cost for secondary posting book of a FA*/

               create fabd_det.
               assign
                  fabd_det.oid_fabd_det   = nextOidValue() 
                  fabd_det.fabd_domain    = global_domain
                  fabd_det.fabd_fa_id     = bfa_mstr.fa_id
                  fabd_det.fabd_fabk_id   = fab_det.fab_fabk_id
                  fabd_det.fabd_entity    = bfa_mstr.fa_entity
                  fabd_det.fabd_resrv     = 0
                  fabd_det.fabd_post      = no
                  fabd_det.fabd_yrper     = l_post_yrper         
                  fabd_det.fabd_facls_id  = bfa_mstr.fa_facls_id
                  fabd_det.fabd_faloc_id  = bfa_mstr.fa_faloc_id
                  fabd_Det.fabd_adj_yrper = l_post_yrper
                  fabd_Det.fabd_peramt    = 0
                  fabd_Det.fabd_accamt    = 0
                  fabd_det.fabd_upper     = 0
                  fabd_det.fabd_accup     = 0
                  fabd_det.fabd_mod_user  = global_userid
                  fabd_det.fabd_mod_date  = today.

                  {us/mf/mfnxtsq1.i  "fabd_det.fabd_domain = global_domain and " fabd_det
                     fabd_seq fabd_sq01 l-seq}


                  fabd_det.fabd_seq   =  l-seq.
                  if recid(fabd_det)  = -1 then.
            end.  /* IF NOT CAN-FIND(FIRST fabd_det */
         end.   /* IF CAN-FIND (first bfab_det */
      end.   /* IF l_cost = 0 */

      /* --------  /* AFTER-ASSIGN-AUDIT-INCLUDE */  ------- */
      do with frame f-1.

         if fab_det.fab_ovramt entered
            or fab_det.fab_ovrdt entered
         then do:

      for each fabd_det
         where fabd_det.fabd_domain = global_domain
           and fabd_fa_id           = fab_det.fab_fa_id
           and fabd_fabk_id         = fab_det.fab_fabk_id
         exclusive-lock:
            delete fabd_det.
      end. /* FOR EACH fabd_det */

      /* ADDED 1ST INPUT PARAMETER AS yes THIS WILL  */
      /* CHECK THAT THE NEXT CALENDAR IS DEFINED FOR */
      /* AN ASSET PLACED IN A SHORT YEAR.            */

      /* ADDED 5TH AND 6TH PARAMETERS AS THE YEAR FOR ADJUSTMENT */
      /* AND DEPRECIATION CALCULATION FOR FOLLOWING YEARS IS     */
      /* NEEDED OR NOT RESPECTIVELY. THESE PARAMETERS WILL BE    */
      /* zero AND no RESPECTIVELY EXCEPT FOR UTILITY utrgendp.p  */
      {us/bbi/gprun.i ""fadpbla.p""
              "(input  yes,
                input  0,
                buffer fa_mstr,
                buffer fab_det,
                input  0,
                input  no,
                output l-err-nbr)"}

      if l-err-nbr <> 0
      then do:
         {us/bbi/pxmsg.i &MSGNUM=l-err-nbr &ERRORLEVEL=3}
         perform-status = "undo".
      end. /* IF l-err-nbr <> 0  */            
   end. /* IF fab_ovramt entered */
end. /* DO WITH FRAME f-1. */

/* ------  END /* AFTER-ASSIGN-AUDIT-INCLUDE */  ----- */
end. /* DO WITH FRAME f-1: */
END PROCEDURE.

PROCEDURE ip-predisplay:
   if perform-status = ""
      and available fab_det
   then
   display-loop:
   do:
      clear frame f-1 all no-pause.
      run ip-displayedits.
      run ip-postdisplay.
   end. /*  DISPLAY-LOOP: */
END PROCEDURE.

PROCEDURE ip-displayedits:
   if available fab_det
   then do:
      assign
         l_cost:format in frame f-1       = l_amt_fmt
         l_bc_cost:format in frame f-1    = l_bc_cost_fmt
         l_sc_cost:format in frame f-1    = l_sc_cost_fmt
         l_salvamt:format in frame f-1    = l_amt_fmt
         l_basis:format in frame f-1      = l_amt_fmt
         fab_ovramt:format in frame f-1   = l_amt_fmt
         l_bc_salvage:format in frame f-1 = l_bc_salvage_fmt
         l_sc_salvage:format in frame f-1 = l_sc_salvage_fmt.
      run ip-display.
   end.
END PROCEDURE.

PROCEDURE ip-display:
   display
      fab_det.fab_fabk_id
      fab_det.fab_life 
      fab_det.fab_ovramt
      l_salvamt
      l_bc_salvage
      l_sc_salvage
      fab_det.fab_ovrdt
      fab_post_oriden     
      l_basis 
      l_cost 
      fab_det.fab_famt_id
      fab_det.fab_date
      l-curr
      l-bc-rate 
      l_bc_cost 
      l-sc-rate 
      l_sc_cost 	
      with frame f-1.
END PROCEDURE.

PROCEDURE ip-postdisplay:
   color display message fab_fabk_id
      with frame f-1.

END PROCEDURE.

PROCEDURE ip-query:
   define input-output parameter perform-status as character no-undo.
   define input-output parameter l-rowid as rowid no-undo.

   if perform-status = "first"
   then do:
      if l-rowid <> ?
      then do:
         reposition q_fab_det to rowid l-rowid no-error.
         get next q_fab_det no-lock.
      end. /* IF l-rowid <> ? */

      if not available fab_det
      then
         get first q_fab_det no-lock.

      if available fab_det
      then
         assign
            perform-status = ""
            l-rowid        = rowid(fab_det).
      else 
      do:
         assign
            perform-status    = ""
            l-rowid           = ?
            frame f-1:visible = true.
         return.
      end. /* ELSE DO: */
   end. /* IF perform-status = "first" */

   if perform-status = "open"
   then do:
      open query q_fab_det for each fab_det
         where rowid(fab_det) = l-rowid no-lock.

      reposition q_fab_det to rowid l-rowid no-error.
      get next q_fab_det no-lock.

      if available fab_det
      then
         assign
            perform-status = ""
            l-rowid        = rowid(fab_det).

      else 
      do:
         get first q_fab_det no-lock.
         if not available fab_det
         then do:
            assign
               perform-status    = ""
               frame f-1:visible = true.
            return.
         end. /* IF NOT available fab_det */
         else
            assign
               perform-status = ""
               l-rowid        = rowid(fab_det).
      end. /* ELSE DO: */
   end. /* IF perform-status = "open" */

   if perform-status = "next"
   then do:
      get next q_fab_det no-lock.
      if available fab_det
      then do:
         assign
            l-rowid        = rowid(fab_det)
            perform-status = "first".
         hide message no-pause.
         run ip-displayedits.
      end. /* IF AVAILABLE fab_det */
      else 
      do:
         perform-status = "".
         /* END OF FILE */
         {us/bbi/pxmsg.i &MSGNUM=20 &ERRORLEVEL=2}
         get prev q_fab_det no-lock.
      end. /* ELSE DO: */
   end. /* IF perform-status = "next" */

   if perform-status = "prev"
   then do:
      get prev q_fab_det no-lock.
      if available fab_det
      then do:
         assign
            l-rowid        = rowid(fab_det)
            perform-status = "first".
         hide message no-pause.
         run ip-displayedits.
      end. /* IF AVAILABLE fab_det */
      else 
      do:
         perform-status = "".
         /* BEGINNING OF FILE */
         {us/bbi/pxmsg.i &MSGNUM=21 &ERRORLEVEL=2}
         get next q_fab_det no-lock.
      end. /* ELSE DO: */
   end. /* IF perform-status = "prev" */

   if perform-status = "update"
      or perform-status = "delete"
   then do:
      get current q_fab_det no-lock.
      if not available fab_det
      then do:
         hide message no-pause.
         /* RECORD NOT FOUND */
         {us/bbi/pxmsg.i &MSGNUM=1310 &ERRORLEVEL=3}
         perform-status = "".
      end. /* IF NOT AVAILABLE fab_det */
   end. /* IF perform-status = "update"  */
END PROCEDURE.

PROCEDURE ip-framesetup:
   if session:display-type = "gui"
   then
      frame f-1:row = 4.5.
   else
      assign
         frame f-1:row           = 4
         frame f-1:box           = true
         frame f-1:centered      = true
         frame f-1:title         = (getFrameTitle("BOOK_DETAIL",17))
         frame f-button:centered = true
         frame f-button:row      = 22.
END PROCEDURE.

PROCEDURE ip-button:
   define input-output parameter perform-status as character
      format "x(25)" no-undo.
   if not batchrun
   then do:
      enable all with frame f-button.
      ststatus = stline[1].
      status input ststatus.
      on choose of b-update
         do:
            assign
               perform-status = self:private-data
               l-focus        = self:handle.
            hide frame f-button no-pause.
         end. /* DO: */

      on choose of b-end
         do:
            assign
               perform-status = self:private-data
               l-focus        = self:handle.
            hide frame f-1 no-pause.
            hide frame f-button no-pause.
         end. /* DO: */
      on cursor-up, f9 anywhere
         do:
            assign
               perform-status = "prev"
               l-focus        = focus:handle.
            apply "go" to frame f-button.
         end. /* DO: */
      on cursor-down, f10 anywhere
         do:
            assign
               perform-status = "next"
               l-focus        = focus:handle.
            apply "go" to frame f-button.
         end. /* DO: */
      on cursor-right anywhere
         do:
            assign
               l-focus = self:handle.
            apply "tab" to l-focus.
         end. /* DO: */
      on cursor-left anywhere
         do:
            l-focus = self:handle.
            if session:display-type = "gui" then
               apply "shift-tab" to l-focus.
            else
               apply "ctrl-u" to l-focus.
         end. /* DO: */
      on esc anywhere
         do:
            if session:display-type = "gui" then
               apply "choose" to b-end in frame f-button.
         end. /* DO: */
      on end-error anywhere
         apply "choose" to b-end in frame f-button.
      on window-close of current-window
         apply "choose" to b-end in frame f-button.
      on go anywhere
         do:
            if (lastkey = keycode("cursor-down")
               or lastkey = keycode("cursor-up")
               or lastkey = keycode("f9")
               or lastkey = keycode("f10"))
            then
               return.
            else
               l-focus = focus:handle.
            apply "choose" to l-focus.
         end. /* DO: */
      wait-for
         go of frame f-button or
         window-close of current-window or
         choose of
         b-update,
         b-end
         focus
         l-focus.
   end. /* IF NOT BATCHRUN */
   else
      set perform-status.
   hide message no-pause.
END PROCEDURE.
